package tt.dz.appserver.mvc.manage;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import tt.dz.appserver.entity.model.ResultMappingEntity;
import tt.dz.appserver.entity.model.dic.City;
import tt.dz.appserver.entity.model.dic.District;
import tt.dz.appserver.entity.model.dic.Province;
import tt.dz.appserver.service.business.DicService;
import tt.dz.appserver.util.Result;
import tt.dz.appserver.util.enums.Response;

/**
 * 字典管理
 * @author USER001
 *
 */

@RestController
@RequestMapping("/manage/dic")
public class DicManager {
	
	@Resource
	DicService dicService;
	
	/**
	 * 省查询
	 **@param provinceid	省id
	 **@param countryid		国家代码
	 **@param provincename	省名称
	 * @return
	 */
	@RequestMapping(value="/ProvinceSelect",produces={"application/json;charset=utf-8"})

	public String provinceselect() {
		//返回数据映射实体
		ResultMappingEntity resultMappingEntity = null;
		
		try {
			//添加反馈
			List<Province> resultObject = dicService.provinceselect();
			
			String code = Response.SUCCESS.getCode();
			String msg = Response.SUCCESS.getMsg();
			
			resultMappingEntity = Result.responseBody(code, msg, resultObject);
						
		} catch(Exception e) {
			e.printStackTrace();
			//异常
			resultMappingEntity = Result.responseBody(Response.RUNTIME_ERROR.getCode(), Response.RUNTIME_ERROR.getMsg(), e.getMessage());
		}
		return resultMappingEntity.toString();
	}	

	/**
	 * 城市查询
	 **@param cityid		城市id
	 * @param provinceid	省id
	 **@param cityname		城市名称
	 * @return
	 */
	@RequestMapping(value="/CitySelect",produces={"application/json;charset=utf-8"})

	public String cityselect(
			@RequestParam(value="provinceid",defaultValue="") String provinceid) {
		//返回数据映射实体
		ResultMappingEntity resultMappingEntity = null;
		
		try {
			//添加反馈
			List<City> resultObject = dicService.cityselectbyprovince(provinceid);
			
			String code = Response.SUCCESS.getCode();
			String msg = Response.SUCCESS.getMsg();
			
			resultMappingEntity = Result.responseBody(code, msg, resultObject);
						
		} catch(Exception e) {
			e.printStackTrace();
			//异常
			resultMappingEntity = Result.responseBody(Response.RUNTIME_ERROR.getCode(), Response.RUNTIME_ERROR.getMsg(), e.getMessage());
		}
		return resultMappingEntity.toString();
	}	
	
	/**
	 * 区县查询
	 **@param districtid	县/区ID
	 * @param cityid		城市id
	 **@param districtname	区/县名称
	 * @return
	 */
	@RequestMapping(value="/DistrictSelect",produces={"application/json;charset=utf-8"})

	public String districtselect(
			@RequestParam(value="cityid",defaultValue="") String cityid) {
		//返回数据映射实体
		ResultMappingEntity resultMappingEntity = null;
		
		try {
			//添加反馈
			List<District> resultObject = dicService.districtselectbycity(cityid);
			
			String code = Response.SUCCESS.getCode();
			String msg = Response.SUCCESS.getMsg();
			
			resultMappingEntity = Result.responseBody(code, msg, resultObject);
						
		} catch(Exception e) {
			e.printStackTrace();
			//异常
			resultMappingEntity = Result.responseBody(Response.RUNTIME_ERROR.getCode(), Response.RUNTIME_ERROR.getMsg(), e.getMessage());
		}
		return resultMappingEntity.toString();
	}	
}
